/**
 * Created by sheep on 2015/12/17.
 */
public class Joining {
    public static void main(String[] args) {
        Sleeper sleeper = new Sleeper("sleeper", 1500),
                grumpy = new Sleeper("grumyp", 1500);
        Joiner dopey = new Joiner("doper", sleeper),
        doc = new Joiner("doc", grumpy);
        grumpy.interrupt();
    }

}


class Sleeper extends Thread {
    private int duration;

    Sleeper(String name, int sleepTime) {
        super(name);
        duration = sleepTime;
        start();
    }

    @Override
    public void run() {
        try {
            sleep(duration);
        } catch (InterruptedException e) {
            e.printStackTrace();
            return;
        }
        System.out.println(getName() + " has awakened");
    }
}


class Joiner extends Thread {
    private Sleeper sleeper;

    public Joiner(String name, Sleeper sleeper) {
        super(name);
        this.sleeper = sleeper;
        start();
    }

    @Override
    public void run() {
        try {
            sleeper.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(getName() + " joiner completed");
    }
}